package com.zzyl.nursing.controller;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.dto.NursingTaskDoDto;
import com.zzyl.nursing.dto.NursingTaskDto;
import com.zzyl.nursing.service.INursingTaskService;
import com.zzyl.nursing.dto.NursingTaskCancelDto;
import com.zzyl.nursing.vo.NursingTaskInfoVo;
import com.zzyl.nursing.vo.NursingTaskVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author baisong
 * @since 2025/10/29 16:20
 */
@RestController
@Slf4j
@RequestMapping("/nursing/nursingTask")
public class NursingTaskController extends BaseController {
    @Autowired
    private INursingTaskService nursingTaskService;

    /**
     * 护理任务分页
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo< List<NursingTaskVo>> getPage(NursingTaskDto dto){
        startPage();
        log.info("--------NursingTaskController.getPage--------护理任务分页，参数为{}",dto );
       List<NursingTaskVo> nursingTaskVoList= nursingTaskService.getPage(dto);
        TableDataInfo dataTable = getDataTable(nursingTaskVoList);

        return dataTable;
    }

    /**
     * 护理任务查询详细信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    private AjaxResult getInfo(@PathVariable Long id){
        log.info("--------NursingTaskController.getInfo--------护理任务查询详细信息，参数为{}",id );
        NursingTaskInfoVo nursingTaskInfoVo= nursingTaskService.getInfo(id);
        return success(nursingTaskInfoVo);
    }

    /**
     * 取消护理任务
     * @return
     */
    @PutMapping("/cancel")
    public AjaxResult cancelTask(@RequestBody NursingTaskCancelDto dto){
        log.info("--------NursingTaskController.cancelTask--------取消护理任务，参数为{}",dto );
        nursingTaskService.cancelTask(dto.getTaskId(),dto.getReason());
       return success();
    }

    /**
     * 执行护理任务
     * @param dto
     * @return
     */
    @PutMapping("/do")
    public AjaxResult doTask(@RequestBody NursingTaskDoDto dto){
        log.info("--------NursingTaskController.doTask--------执行护理任务，参数为{}",dto );
        nursingTaskService.doTask(dto);
        return success();
    }

    /**
     * 护理任务改期
     * @param dto
     * @return
     */
    @PutMapping("/updateTime")
    public AjaxResult updateTaskTime(@RequestBody NursingTaskDoDto dto){
        log.info("--------NursingTaskController.updateTaskTime--------护理任务改期，参数为{}",dto );
        nursingTaskService.updateTaskTime(dto);
        return success();
    }

}
